﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeChatSDK.Core
{
    public class Foundation
    {
        public Foundation()
        {

        }
        /// <summary>
        /// 获取系统的Token
        /// </summary>
        /// <returns></returns>
        public string GetAccessToken()
        {
            CommunicateHelper conn = CommunicateHelper.init();

            string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", conn.AppID, conn.AppSecret);
            string rec = conn.HttpGet(url);
            JObject json = JObject.Parse(rec);
            if (json == null)
            {
                return string.Empty;
            }

            if (string.IsNullOrEmpty((string)json["errcode"]))
            {
                string token = (string)json["access_token"];
                DateTime expire = DateTime.Now.AddSeconds((int)json["expires_in"]);

                return token;
            }
            else
            {
                return string.Empty;
            }
        }

        public string GetWeChatIP()
        {
            return string.Empty;
        }
    }
}
